
//================v1要点总结===============
/**
 * 1.双指针比较合并，未考虑对输入链表影响
 * 2.是合并，所以注意游标移动的时机
 * 3.注意考虑合并后的有序
 */


function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}

/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var mergeTwoLists = function (l1, l2) {
    if (!l1) {
        return l2
    }
    if (!l2) {
        return l1
    }
    let cur1 = l1
    let cur2 = l2
    // 赋初始值,声明一个空节点
    let rslt = new ListNode(-1)
    let cur = rslt
    do {
        if (cur1.val < cur2.val) {
            cur.next = cur1
            cur1 = cur1.next
        } else {
            cur.next = cur2
            cur2 = cur2.next
        }
        cur = cur.next
    } while (cur1 && cur2)

    //拼接剩余的
    cur1 ? cur.next = cur1 : cur.next = cur2
    return rslt.next
};

console.log(mergeTwoLists())